package com.ruoyi.base.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.base.mapper.IndustryMapper;
import com.ruoyi.base.domain.Industry;
import com.ruoyi.base.service.IIndustryService;

/**
 * 行业列表Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-23
 */
@Service
public class IndustryServiceImpl implements IIndustryService 
{
    @Autowired
    private IndustryMapper industryMapper;

    /**
     * 查询行业列表
     * 
     * @param industryId 行业列表主键
     * @return 行业列表
     */
    @Override
    public Industry selectIndustryByIndustryId(Long industryId)
    {
        return industryMapper.selectIndustryByIndustryId(industryId);
    }

    /**
     * 查询行业列表列表
     * 
     * @param industry 行业列表
     * @return 行业列表
     */
    @Override
    public List<Industry> selectIndustryList(Industry industry)
    {
        return industryMapper.selectIndustryList(industry);
    }

    /**
     * 新增行业列表
     * 
     * @param industry 行业列表
     * @return 结果
     */
    @Override
    public int insertIndustry(Industry industry)
    {
        //1.验证行业名称是否重复
        QueryWrapper<Industry> qw = new QueryWrapper<>();
        qw.lambda().eq(Industry::getIndustryName, industry.getIndustryName());
        List<Industry> list = industryMapper.selectList(qw);

        if (list.size() > 0) {
            throw new RuntimeException("行业名称已存在，不可使用");
        }

        return industryMapper.insert(industry);
    }

    /**
     * 修改行业列表
     * 
     * @param industry 行业列表
     * @return 结果
     */
    @Override
    public int updateIndustry(Industry industry)
    {
        return industryMapper.updateIndustry(industry);
    }

    /**
     * 批量删除行业列表
     * 
     * @param industryIds 需要删除的行业列表主键
     * @return 结果
     */
    @Override
    public int deleteIndustryByIndustryIds(Long[] industryIds)
    {
        //1.验证传进来的行业id
        if (industryIds.length == 0) {
            throw new RuntimeException("行业id不能为空");
        }
        return industryMapper.deleteIndustryByIndustryIds(industryIds);
    }

    /**
     * 删除行业列表信息
     * 
     * @param industryId 行业列表主键
     * @return 结果
     */
    @Override
    public int deleteIndustryByIndustryId(Long industryId)
    {
        if (industryId == null) {
            throw new RuntimeException("行业id不能为空");
        }
        return industryMapper.deleteIndustryByIndustryId(industryId);
    }
}
